window.onload=function(){
    new Vue({
        el:'#box',
        data:{
            myData:[],
            attrName:'',
            attrNamen:'',
            age:'',
            nowIndex:-100,
            edit:null
        },
        methods:{
            //添加文本框
            add:function(){
                if(this.attrName!=null&this.attrName.length>0){
                    this.myData.push({
                        attrName:this.attrName,
                    });
                    console.log(this.myData);
                    this.attrName='';
                }
            },
            //点击文字
            onedit:function(attrName,index){
                this.edit=null;
                this.attrNamen=attrName;
                this.edit=index;
            },
            onck:function(){
                this.edit=null;
            },
            //离开文字输入框
            edits:function(index){
                this.myData.splice(index,1);
                if(this.attrNamen!=null&this.attrNamen.length>0){
                    this.myData.push({
                        attrName:this.attrNamen,
                    });
                    console.log(this.myData);
                    this.attrNamen='';
                }
            },//删除
            deleteMsg:function(n){
                if(n==-2){
                    this.myData=[];
                }else{
                    this.myData.splice(n,1);
                }
            }
        }
    });
};